Attribute VB_Name = "modACAPI"
Option Explicit

' This file is part of Nightowl.
'
' Nightowl is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.

' Nightowl is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.

' You should have received a copy of the GNU General Public License
' along with Nightowl.  If not, see <http://www.gnu.org/licenses/>.



' These are API function calls that are
' used within Nightowl.
' We house them in a separate module to keep
' confusion down in the main module.

Private Declare Function GetUserNameAPI Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, _
    nSize As Long) As Long

Private Declare Function GetComputerName Lib "kernel32" Alias _
    "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Declare Function GetKeyState Lib "User32" (ByVal nVirtKey As Long) As Integer

Private Declare Sub GetKeyboardState Lib "User32" (ByVal lpKeyState As String)
Private Declare Sub SetKeyboardState Lib "User32" (ByVal lpKeyState As String)



Public Function ComputerName() As String
     
    ' Returns the name of the local computer.
    Dim Buffer As String * 512, Length As Long
    Length = Len(Buffer)
    If GetComputerName(Buffer, Length) Then
        ' this API returns non-zero if successful,
        ' and modifies the length argument
        ComputerName = Left(Buffer, Length)
    End If
     
End Function

Public Function GetUserName() As String
    Dim sBuffer As String
    Dim lSize As Long
    Dim lRV As Long
     
    lSize = 255
    sBuffer = String(lSize, &H0)
     
    lRV = GetUserNameAPI(sBuffer, lSize)
     
    If lRV <> 0 Then
        GetUserName = Left(sBuffer, lSize - 1) ' -1 to remove trailing null character
    Else
        GetUserName = ""
    End If
End Function

